#!/usr/bin/perl
require "accounts.pl";

my (%groupmember, @grouplist, $i, $table_length, $displaymembers);

&header($text{'index_title'}, "", "index", 0, 1);

@grouplist = &get_local_group_list(\%groupmember);

print "<form name=formgroup action='index.cgi' method=post onsubmit='return onsubmit_form();'>\n";

print "<table class=mode1 width=100% border=0 cellpadding=0 cellspacing=0>\n";
print "<tr><td valign=top width=78%>\n"; #main table td1 --> grouplist

print "<div style='valign:top;width:100%;height:300;overflow:auto'>";

print "<table class=mode1 width=100% border=0 cellpadding=0 cellspacing=0>\n";
print "<tr class=title1><th width=35% align=left>$text{'index_tr_name'}</th><th width=65% align=left>$text{'index_tr_members'}</th></tr>";

$i = 0; $table_length = 0;
while($i < @grouplist)
{
	#print "<p>", $groupmember{$grouplist[$i]};
	if($i % 2)
	{
		$trclass = "class=mode2";
	}
	else
	{
		$trclass = "class=mode1";
	}
	$displaymembers = &display_5_members($groupmember{$grouplist[$i]});
	print "<tr $trclass><td><input type=radio name=groupname value='$grouplist[$i]' onclick='document.forms[0].groupselect.value = \"$grouplist[$i]\"; document.forms[0].memberselect.value = \"$groupmember{$grouplist[$i]}\";'>$grouplist[$i]</td><td>$displaymembers</td></tr>\n";
	$i++;
	$table_length++;
}

print "</table>\n";

print "<input name=submitbutton type=hidden value=''>";
print "<input name=groupselect type=hidden value=''>";
print "<input name=memberselect type=hidden value=''>\n";

print "</div>";

print "</td><td valign=top align=center>\n";     #table2  submit table
print "<table>\n";
print "<tr><td><input name=btncreate class=button type=submit value=\"$text{'index_submit_create'}\" onclick=\'return on_create_click()'></td></tr>\n";
print "<tr><td><input name=btnmodify class=button type=submit value=\"$text{'index_submit_modify'}\" onclick='return on_modify_click($table_length, \"$text{'error_msg_noselect_item'}\");'></td></tr>\n";
print "<tr><td><input name=btndelete class=button type=submit value=\"$text{'index_submit_delete'}\" onclick='return on_delete_click($table_length, \"$text{'error_msg_noselect_item'}\", \"$text{'index_delete_msg'}\");'></td></tr>\n";
print "</table>\n";  #table2

print "</table>\n";  #main table

print "</form>\n";

#print "<hr>";

print <<EOF;
<script>
function onsubmit_form()
{
        document.forms[0].btncreate.disabled = true;
        document.forms[0].btnmodify.disabled = true;
        document.forms[0].btndelete.disabled = true;
}

function on_create_click()
{
	document.forms[0].submitbutton.value="create";
	document.forms[0].action = "edit_group.cgi";
}

function on_modify_click(length, error_msg)
{
	var i;
	var find = 0;

	if(length < 2)
	{
		if(length < 1)
		{
			return false;
		}
		else
		{
			if(document.forms[0].groupname.checked)
			{
				find = 1;
			}
		}
	}
	else
	{
		for(i = 0; i < length; i++)
		{
			if(document.forms[0].groupname[i].checked)
			{
				find = 1;
			}
		}
	}

	if(find == 0)
	{
		alert(error_msg);
		return false;
	}

	document.forms[0].submitbutton.value = "modify";
	document.forms[0].action = "edit_group.cgi";
}

function on_delete_click(length, error_msg, delete_msg)
{
	var i;
	var find = 0;

	if(length < 2)
	{
		if(length < 1)
		{
			return false;
		}
		else
		{
			if(document.forms[0].groupname.checked)
			{
				find = 1;
			}
		}
	}
	else
	{
		for(i = 0; i < length; i++)
		{
			if(document.forms[0].groupname[i].checked)
			{
				find = 1;
			}
		}
	}

	if(find == 0)
	{
		alert(error_msg);
		return false;
	}

        if(!confirm(delete_msg))
        {
                return false;
        }

	document.forms[0].submitbutton.value = 'delete';
	document.forms[0].action = 'delete_group.cgi';
}

</script>
EOF


&footer("/", $text{'index'});
